package com.liruo.treasureattic.common.util;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author:liruo
 * @Date:2023-02-06-15:56:30
 * @Desc
 */
public class StringUtils {
    public static List<String> splitBySize(String s, int size){
        ArrayList<String> split = new ArrayList<>(s.length() / size);
        int i = 0;
        for (; i < s.length(); i+=size) {
            if(i + size  <= s.length()){
                split.add(s.substring(i, i + size));
            }else{
                split.add(s.substring(i));
            }
        }
        return split;
    }
    public static List<String> splitBySizeRight(String s, int size){
        LinkedList<String> split = new LinkedList<>();
        int i = s.length();
        for (; i > 0; i-=size) {
            if(i - size  >= 0){
                split.addFirst(s.substring(i - size, i));
            }else{
                split.addFirst(s.substring(0, i));
            }
        }
        return split;
    }
}
